# -*- coding: utf-8 -*-
import Queue, threading

username = "fliang"
password = "finalion"
SleepSeconds = 1
# science direct, wily interscience, padd,EBSCO(asp bsp),IOp,oxiford,nature,
normal_dbs = {'2':'CNKI,万方,清华同方',
         #'24':'CNKI',
         '10':'CNKI医学,SpringerLink',
         '1':'CNKI学位论文',
         #'41':'CNKI学位论文镜像,ebsco(asp bsp)',
         '26':'Science Direct',
         '46':'Wiley interscience',
         '47':'IOP',
         #'253':'IOP镜像',
         '82':'oxford',
         '58':'nature',
         #'275':'nature',
         '45':'ACS',
         '17':'GSW',
         '226':'Frontiers in China',
         '101':'RSC',
         '279':'RSC1',
         '261':'RSC2',
         '30':'JSTOR',
         '205':'Portland Press',
         '89':'Journals of the American Society of Plant Biologists',
         '286':'EBSCO_MasterFILE Premier',
         '54':'SAGE',
         '227':'bioline',
         '13':'IEEE',
         }

login_url = "http://www.firstdrs.com/admin/login.do"

minsize = 12000

errorsize = [0,51,123,163,1149,1403,1419,1494,2519,16201]
#51: <meta http-equiv="refresh" content="0;URL=/kns50/">
#1149,1403,1494: 对不起，您的请求未经授权服务器拒绝该下载！
#123: alert('对不起，您的操作太过频繁。');
#16201: CNKI保密
allpatterns = {'24':(r"BORDER=0> <a href='(.*?)' target='_blank'><b>PDF下载</b>", #'http://epub.cnki.net'
                   r' "><a target="_blank" href="(.*?)"><b>PDF下载</b>',),  #http://www.cnki.net/kcms/
            '2':(r"BORDER=0> <a href='(.*?)' target='_blank'><b>下载阅读PDF格式全文</b>", #"http://dlib.edu.cnki.net"
                  r"<a class=\"downloadft\" href='(.*?)'>",), #"http://d.g.wanfangdata.com.cn
            '1':(r"<IMG SRC='.*?zhengben.gif' WIDTH='16' HEIGHT='16' BORDER=0><a href='(.*?)' target='_blank'>整本下载",), # cnki学位论文 nh
            '10':(),
            '26':(r"<li class=\"featureCount\">.*?pdfWin=window.open\('(.*?)'.*?title=\"Download PDF\"",),
            '46':(r'<iframe id="pdfDocument" src="(.*?)"',),
            '58':(r'<li class="download-pdf"><a href="(.*?)">',),
            '82':(r'<frame src="(.*?)" name="ContentsPage"',),
            '45':(),
            '17':(),
            '226':(),
            '101':(),
            '279':(),
            '261':(),
            '47':(),
            '30':(),
            '205':(),
            '89':(),
            '286':(),
            '54':(),
            '227':(),
            '13':(r'<frame src="(http://.*?)" frameborder=0',),
            }

#数据库设置
db_host = 'localhost'
db_user = 'root'
db_passwd = ''
main_db = 'firstdrs'


#任务过滤队列，负责检查队列中的任务是否有有效下载链接，如果有把任务放入下载队列
q_filter = Queue.Queue()
FilterThreadNumber = 5
#数据库检查队列
q_db = Queue.Queue()
CheckDbThreadNumber = 5
#下载队列
download_queue = Queue.Queue()
DownloadThreadNumber = 10

lock = threading.RLock()

auto_download = False#True

